<?php


namespace App\Exports;


use App\Models\AssetStock;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class AssetStockExport implements FromCollection, WithHeadings
{

    /**
     * @return Collection
     */
    public function collection()
    {
        return AssetStock::all()->map(function(AssetStock $asset){
            return [
                $asset->id,
                $asset->name,
                $asset->product_model_number,
                $asset->marking_price_per_unit,
                $asset->bid_price_per_unit,
                $asset->init_quantity,
                $asset->available_quantity,
                $asset->checkout_quantity,
                $asset->total_quantity,
                $asset->category->name,
                $asset->subCategory->name,
                $asset->brand->name,
                $asset->affiliation->name,
                $asset->keeper->name,
                $asset->vendor->name,
                $asset->location->name
            ];
        });
    }

    /**
     * @return array
     */
    public function headings(): array
    {
        return [
            '序号',
            '名称',
            '物品编码',
            '单位/市场价',
            '单位/购入价',
            '初始数量',
            '有效数量',
            '借出数量',
            '总数',
            '主类',
            '副类',
            '品牌',
            '归属',
            '保管人',
            '供应商',
            '仓库',
        ];
    }
}
